<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2019/3/18
 * Time: 16:02
 */

namespace app\controllers;

use Yii;
class TaskController extends BaseController
{
    /** @var \common\logics\taskcommod\TaskCommodLogic $TaskCommodService ***/
    private $TaskCommodService;
    /** @var \common\logics\taskorder\TaskOrderLogic $TaskOrderService **/
    private $TaskOrderService;
    public function init()
    {
        $this->TaskCommodService = Yii::$container->get("TaskCommodService");
        $this->TaskOrderService = Yii::$container->get("TaskOrderService");
        return parent::init(); // TODO: Change the autogenerated stub
    }

    //任务列表
    public function actionList()
    {
        $param = [
            "buy_id" => Yii::$app->request->post("buy_id",0),           //买号id
            "plat_type" => Yii::$app->request->post("plat_type",0),     //平台类型 1.淘宝，2.天猫
            "task_type" => Yii::$app->request->post("task_type",0),     //任务类型
            "tb_id" => Yii::$app->request->post("tb_id",0),             //买号id
            "port_type" => Yii::$app->request->post("port_type",0),     //端口类型 1.电脑端，2.手机端
            "task_class" => Yii::$app->request->post("task_class",0),     //任务分类  1.常规任务 2.花呗信用卡 3. 加赏任务
            "limit" => Yii::$app->request->post("limit",10),              //每页条数
            "page_num" => Yii::$app->request->post("page_num",1),           //当前页数
        ];
        $result = $this->TaskCommodService->getTaskList($param);
        return $result;
    }
    //接手任务
    public function actionReceiveTasks()
    {
        $param = [
            "buy_id" => Yii::$app->request->post("buy_id",0),               //买手用户id
            "task_commod_id" => Yii::$app->request->post("task_commod_id",0),//任务id
            "tb_id" => Yii::$app->request->post("tb_id",0),                 //买号id
            "safetyCode" => Yii::$app->request->post("safetyCode",''),      //安全码
        ];
        $result = $this->TaskCommodService->receiveTasks($param);
        return $result;
    }
    //核对链接 第一步 和第三步
    public function actionCheckLinks()
    {
        $param = [
            "bb_url" => Yii::$app->request->post("bb_url",""),                  //验证宝贝链接
            "task_order_id" => Yii::$app->request->post("task_order_id",0),     //子任务id
            "buy_id" => Yii::$app->request->post("buy_id",0),                   //买手id
            "safetyCode" => Yii::$app->request->post("safetyCode",''),          //安全码
        ];
        $result = $this->TaskOrderService->checkLink($param);
        return $result;
    }
    //搜索商品 第一步操作  核对链接之后 提交核对结果
    public function actionCheckLinksNext()
    {
        $param  = [
            "task_order_id" => Yii::$app->request->post("task_order_id",0),     //子任务id
            "buy_id" => Yii::$app->request->post("buy_id",0),                   //买手id
            "safetyCode" => Yii::$app->request->post("safetyCode",''),          //安全码
        ];
        $result = $this->TaskOrderService->chekLinkNext($param);
        return $result;
    }


    //上传关键子截图 第二步
    public function actionUploadKeywordsImg()
    {
        $param = [
            "keywords_url" => Yii::$app->request->post("keywords_url",""),                  //上传关键字截图
            "task_order_id" => Yii::$app->request->post("task_order_id",0),                 //子任务id
            "buy_id" => Yii::$app->request->post("buy_id",0),                               //买手id
            "safetyCode" => Yii::$app->request->post("safetyCode",''),                      //安全码
        ];
        $result = $this->TaskOrderService->uploadImg($param);
        return $result;
    }

    //浏览任务 第三步
    public function actionBrowseTask()
    {
        $param = [
            "bb_url" => Yii::$app->request->post("bb_url",""),                      // 宝贝链接
            "task_order_id" => Yii::$app->request->post("task_order_id",""),        //子任务单号
            "buy_id" => Yii::$app->request->post("buy_id",0),                       //买手用户id
            "safetyCode" => Yii::$app->request->post("safetyCode",''),                      //安全码
        ];
        $result = $this->TaskOrderService->browseTask($param);
        return $result;
    }
    //提交任务
    public function actionSubmitTask()
    {
        $param = [
            "task_order_id" => Yii::$app->request->post("task_order_id",""),        //子任务单号
            "buy_id" => Yii::$app->request->post("buy_id",0),                       //买手用户id
            "actual_price" => Yii::$app->request->post("actual_price",0),           //实际付款金额
            "purchase_num" => Yii::$app->request->post("purchase_num",0),           //每单件数
            "pay_order_num" => Yii::$app->request->post("pay_order_num",''),        //付款订单号
            "addr_url" => Yii::$app->request->post("addr_url",''),                  //上传地址详情截图
            "pay_url" => Yii::$app->request->post("pay_url",''),                    //上传付款金额截图
            "leave_message" => Yii::$app->request->post("leave_message",''),        //订单留言
            "safetyCode" => Yii::$app->request->post("safetyCode",''),              //安全码
        ];
        $result = $this->TaskOrderService->submitTask($param);
        return $result;
    }
    //驳回返款
    public function actionRejectRefunds()
    {
        $param = [
            "task_order_id" => Yii::$app->request->post("task_order_id",""),          //子任务单号
            "buy_id" => Yii::$app->request->post("buy_id",0),                          //买手用户id
            "actual_refunds" => Yii::$app->request->post("actual_refunds",0),         //审核返款金额
            "safetyCode" => Yii::$app->request->post("safetyCode",""),                //安全码
        ];
        $result = $this->TaskOrderService->rejectRefunds($param);
        return $result;
    }
    //上传好评图片
    public function actionUploadPositive()
    {
        $param = [
            "task_order_id" => Yii::$app->request->post("task_order_id",""),        //子任务单号
            "buy_id" => Yii::$app->request->post("buy_id",0),                       //买手用户id
            "parise_url" => Yii::$app->request->post("parise_url",''),              //好评评语截图
            "tao_parise_url" => Yii::$app->request->post("tao_parise_url",""),      //淘宝好评截图
            "safetyCode" => Yii::$app->request->post("safetyCode",""),              //安全码
        ];
        $result = $this->TaskOrderService->uploadPositive($param);
        return $result;
    }

    //查询子订单任务
    public function actionGetTaskOrder()
    {
        $param = [
            "task_order_num" => Yii::$app->request->post("task_order_num",""),        //子任务单号
            "buy_id" => Yii::$app->request->post("buy_id",0),                          //买手用户id
        ];
        $result = $this->TaskOrderService->getTaskOrder($param);
        return $result;
    }
    //获取任务列表
    public function actionGetTaskOrderList()
    {
        $param = [
            "buy_id" => Yii::$app->request->post("buy_id",0),                   //买手用户id
            "order_status" => Yii::$app->request->post("order_status",0),       //订单状态 1 已接手 待提交，4.已提交待发货，5，已发货待收货，6.已收货待返款，7.已返款待确认，8.已完成，9.已驳回，10.已放弃
            "tbname" => Yii::$app->request->post("tbname",""),                  //买号
            "plat_type" => Yii::$app->request->post("plat_type",0),             //平台 1.淘宝， 2.天猫
            "task_type" => Yii::$app->request->post("task_type",0),             //任务类型
            "page_num" => Yii::$app->request->post("page_num",1),               //当前页数
            "limit" => Yii::$app->request->post("limit",10),                    //每页条数
        ];
        $result = $this->TaskOrderService->getTaskOrderList($param);
        return $result;
    }
    //放弃任务
    public function actionGiveUpTask()
    {
        $param = [
            "task_order_id" => Yii::$app->request->post("task_order_id",0),         //子任务订单id
            "buy_id" => Yii::$app->request->post("buy_id",0),                         //买手用户id
            "safetyCode" => Yii::$app->request->post("safetyCode",""),                  //安全码
        ];
        $result = $this->TaskOrderService->geiveUpTask($param);
        return $result;
    }
    //确认收货
    public function actionConfirmReceipt()
    {
        $param = [
            "task_order_id" => Yii::$app->request->post("task_order_id",0),         //子任务订单id
            "buy_id" => Yii::$app->request->post("buy_id",0),                         //买手用户id
            "safetyCode" => Yii::$app->request->post("safetyCode",""),                  //安全码
        ];
        $result = $this->TaskOrderService->confirmReceipt($param);
        return $result;
    }
    //确认返款
    public function actionConfirmRefunds()
    {
        $param = [
            "task_order_id" => Yii::$app->request->post("task_order_id",0),         //子任务订单id
            "buy_id" => Yii::$app->request->post("buy_id",0),                         //买手用户id
            "safetyCode" => Yii::$app->request->post("safetyCode",""),                  //安全码
        ];
        $result = $this->TaskOrderService->confirmRefunds($param);
        return $result;
    }

}